// Copyright (c) 2002 HTHK
//******************************************************************/
//Modification History
//******************************************************************/
//CR log no 1054: By Oscar Bai  Date:2003/02
//CR log no 1266: By Ploy Li on 2004-04-27
//******************************************************************/

package admin.system.user;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import com.ffpc.servlet.*;
import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;
import com.system.userMultiRole.UserMultiRoleBean;
import com.system.userMultiRole.UserMultiRoleProcess;

/**
 * A Class class.
 * <P>
 * @author HTHK
 */
public class UserSearch
  extends DBServlet {

  @Override
protected String perform(  HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
  {
      UserBean user = UserProcess.createBean();
      user.setUser_id(request.getParameter("user_id"));
      user.setUser_name(request.getParameter("user_name"));
      UserBean[] users = UserProcess.find(this.getConnection(),user);
      
//Modified by Poly Li , CR log no 1266, on 2004-4-23 10:01
//--------Add by poly-------------      
      UserMultiRoleBean userMultiRole = UserMultiRoleProcess.createBean();
      userMultiRole.setUser_id(request.getParameter("user_id"));
      UserMultiRoleBean[] userMultiRoles = UserMultiRoleProcess.find(this.getConnection(),userMultiRole);
//--------------------------------//

      if (users==null || users.length==0)
      {
          message.setMessage("No record, please input another criteria.");
          return "system/UserSearch.jsp";
      }
      else if (users.length==1)
      {
          request.setAttribute("user",users[0]);
          request.setAttribute("userMultiRoles",userMultiRoles);

//End modified by Poly

          return "system/User.jsp?formAction=Update";
      }
      else
      {
          request.setAttribute("users",users);
          return "system/UserList.jsp";
      }
  }
}


